﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace PersonaLibrary.Converters
{
    public class EmployeeNameConverter : IMultiValueConverter
    {
        public object Convert(object[] value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value.Length == 3)
            {
                StringBuilder builder = new StringBuilder();
                if (value[0] != null)
                {
                    builder.Append(value[0].ToString());
                }
                if (value[1] != null)
                {
                    builder.Append(" ");
                    builder.Append(value[1].ToString());
                }
                if (value[2] != null)
                {
                    builder.Append(" ");
                    builder.Append(value[2].ToString());
                }
                return builder.ToString();
            }
            
            return null;
        }

        public object[] ConvertBack(object value, System.Type[] targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (targetType.Length == 3)
            {
                string[] result = new string[3];
                string[] splitted = value.ToString().Replace("  ", " ").Split(" ".ToCharArray());

                for(int i = 0; i < splitted.Length; i++) result[i] = splitted[i];
                return result;
            }
            return null;
        }
    }
}
